package com.xbongbong.saas.enums;

import com.xbongbong.saas.enums.business.ProductSerialBalanceEnum;
import com.xbongbong.saas.enums.business.SerialStatusEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * 选择序列号关系枚举
 */
@Getter
public enum LinkProductSelectSerialEnum {
    // 采购退货单
    RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(), SerialStatusEnum.IN_STOCK.getCode()),
    // 采购退货出库单
    RETURNED_PURCHASE_OUTSTOCK(XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(), XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), SerialStatusEnum.IN_STOCK.getCode()),
    // 销售出库
    CONTRACT_OUTSTOCK(XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(), null, SerialStatusEnum.IN_STOCK.getCode()),
    // 退货退款
    REFUND(XbbRefTypeEnum.REFUND.getCode(), XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(), SerialStatusEnum.OUT_STOCK.getCode()),
    // 销售退货入库单
    REFUND_INSTOCK(XbbRefTypeEnum.REFUND_INSTOCK.getCode(), XbbRefTypeEnum.REFUND.getCode(), SerialStatusEnum.OUT_STOCK.getCode()),
    // 生产领料
    PRODUCTION_MATERIEL_OUTSTOCK(XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(), null, SerialStatusEnum.IN_STOCK.getCode()),
    // 生产退料单
    RETURNED_MATERIEL_INSTOCK(XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode(), XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(), SerialStatusEnum.OUT_STOCK.getCode()),
    // 装配出入库单
    ASSEMBLE_OUTSTOCK(XbbRefTypeEnum.ASSEMBLE.getCode(), null, SerialStatusEnum.IN_STOCK.getCode()),
    // 调拨
    TRANSFER(XbbRefTypeEnum.TRANSFER.getCode(), null, SerialStatusEnum.IN_STOCK.getCode()),
    // 工单出库
    WORK_ORDER_OUTSTOCK(XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode(), null, SerialStatusEnum.IN_STOCK.getCode()),
    //
    UNKNOWN(404, null, null);

    // 表单类型
    private final Integer businessType;

    // 选择序列号源表单
    private final Integer linkBusinessType;

    // 可选序列号状态
    private final Integer status;

    LinkProductSelectSerialEnum(Integer businessType, Integer linkBusinessType, Integer status) {
        this.businessType = businessType;
        this.linkBusinessType = linkBusinessType;
        this.status = status;
    }

    public static LinkProductSelectSerialEnum getByBusinessType(Integer businessType) {
        for (LinkProductSelectSerialEnum linkProductSelectSerialEnum : LinkProductSelectSerialEnum.values()) {
            if (Objects.equals(businessType, linkProductSelectSerialEnum.getBusinessType())) {
                return linkProductSelectSerialEnum;
            }
        }
        return UNKNOWN;
    }
}
